package com.mstore.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.mstore.pojo.Account;
import com.mstore.pojo.BAnnouncement;
import com.mstore.service.BAnnouncementService;
import com.opensymphony.xwork2.ActionContext;

/**
 * 积分公告
 */
public class BAnnouncementAction extends BaseAction {

	private static final long serialVersionUID = 4005667552865153130L;

	private BAnnouncementService bAnnouncementService;

	private Map<String, Object> session = ActionContext.getContext()
			.getSession();

	private BAnnouncement bAnnouncement = new BAnnouncement();

	private List<BAnnouncement> listBA = new ArrayList<BAnnouncement>();

	/**
	 * 查询所有
	 */
	public String selectBAnnouncement() {
		Account account = (Account) session.get("account");

		bAnnouncement.setEaId(account.getId());
		listBA = bAnnouncementService.selectAll(bAnnouncement);
		return "selectBannouncementSuccess";
	}

	/**
	 * 保存所有
	 */
	public String saveBAnnouncement() {
		Account account = (Account) session.get("account");
		bAnnouncement.setEaId(account.getId());
		bAnnouncement.setCreateTime(getCreateTime());
		bAnnouncementService.saveBAnnouncement(bAnnouncement);
		return "saveBAnnouncementSuccess";
	}

	/**
	 * 查询单个
	 */
	public String selectById() {
		bAnnouncement = bAnnouncementService.selectById(bAnnouncement);
		session.put("bAnnouncement", bAnnouncement);
		return "selectByIdSuccess";
	}

	/**
	 * 删除
	 */
	public String deleteBAnnouncement() {
		bAnnouncementService.deleteBAnnouncement(bAnnouncement);
		return "deleteBAnnouncementSuccess";
	}

	/**
	 * 更新
	 */
	public String updateBAnnouncement() {
		String announcement = bAnnouncement.getAnnouncement();
		announcement = announcement.replaceAll("'", "");
		bAnnouncement.setAnnouncement(announcement);
		bAnnouncementService.updateBAnnouncement(bAnnouncement);
		return "updateBAnnouncementSuccess";
	}

	/**
	 * 预览
	 */
	public String lookBAnnouncement() {
		bAnnouncement = bAnnouncementService.selectById(bAnnouncement);
		return "lookBAnnouncementSuccess";
	}

	public BAnnouncementService getbAnnouncementService() {
		return bAnnouncementService;
	}

	public void setbAnnouncementService(
			BAnnouncementService bAnnouncementService) {
		this.bAnnouncementService = bAnnouncementService;
	}

	public BAnnouncement getbAnnouncement() {
		return bAnnouncement;
	}

	public void setbAnnouncement(BAnnouncement bAnnouncement) {
		this.bAnnouncement = bAnnouncement;
	}

	public List<BAnnouncement> getListBA() {
		return listBA;
	}

	public void setListBA(List<BAnnouncement> listBA) {
		this.listBA = listBA;
	}

}
